const cloud = require('wx-server-sdk');
const fs = require('fs');

// const db = cloud.database({
// 	env:'roseannepark'
// })
const db = cloud.database()


exports.main = async (event, context) => {
	const result = Buffer.isBuffer(event.data.data);
	console.log(event)
	buffer = Buffer.from(event.data.data);
	let response = await cloud.openapi.security.imgSecCheck({
		media: {
			contentType: event.fileType,
			value: buffer
		}
	});
  console.log(response);
  let data = null;
  if(response.errCode == 0){
    const res = await cloud.uploadFile({
      cloudPath: event.path,
      fileContent: buffer
    });
    data = {'msg':'ok','data':res}
  }else{
    data = {'msg':'fail','data':response}
  }
	return data
}
